package canchaFulbito.servletacceso;

import java.io.IOException;
import java.text.ParseException;
import java.text.SimpleDateFormat;
import java.sql.Date;

import javax.servlet.RequestDispatcher;
import javax.servlet.ServletException;
import javax.servlet.http.HttpServlet;
import javax.servlet.http.HttpServletRequest;
import javax.servlet.http.HttpServletResponse;
import canchaFulbito.excepcion.DAOExcepcion;
import canchaFulbito.negocio.SeguridadNegocio;
/**
 * Servlet implementation class InsertarPersonaServlet
 */
public class InsertarPersonaServlet extends HttpServlet {
	private static final long serialVersionUID = 1L;
       
    /**
     * @see HttpServlet#HttpServlet()
     */
    public InsertarPersonaServlet() {
        super();
        // TODO Auto-generated constructor stub
    }

	/**
	 * @see HttpServlet#doGet(HttpServletRequest request, HttpServletResponse response)
	 */
	protected void doGet(HttpServletRequest request, HttpServletResponse response) throws ServletException, IOException {
		// TODO Auto-generated method stub
	}

	/**
	 * @see HttpServlet#doPost(HttpServletRequest request, HttpServletResponse response)
	 */
	protected void doPost(HttpServletRequest request, HttpServletResponse response) throws ServletException, IOException {
		// TODO Auto-generated method stub
		
				SeguridadNegocio neg = new SeguridadNegocio();
				int IdTipDoc=0;
				int RolId=0;
				String msg="";
				RequestDispatcher rd;
				
				System.out.print("IdTipoPersona : " + request.getParameter("txtFechaNac"));
				try {
					if (request.getParameter("NomPersona")!="" & request.getParameter("NomPaterno")!=null & request.getParameter("NomMaterno")!=null &
							request.getParameter("NomMaterno")!=null & request.getParameter("IdGenero")!="" & request.getParameter("txtNumDoc")!=null &  
							request.getParameter("txtCorreo")!=null & request.getParameter("txtPass")!=null & request.getParameter("txtFechaNac")!=null & 
							request.getParameter("txtCelular")!=null&request.getParameter("IdTipDoc")!="" & request.getParameter("IdTipoPersona") != ""
							)
					{
						
						String NomPersona = request.getParameter("NomPersona");
						
						String NomPaterno = request.getParameter("NomPaterno");
						String NomMaterno = request.getParameter("NomMaterno");
						String Sexo       = request.getParameter("IdGenero");
												
						String NumDocumento = request.getParameter("txtNumDoc");
						String NomEmail = request.getParameter("txtCorreo");
						String NomPass = request.getParameter("txtPass");
						String FechaNaciento =  request.getParameter("txtFechaNac");						
						String NumCelular = request.getParameter("txtCelular");
						String Estado = "A";			
						IdTipDoc =Integer.parseInt(request.getParameter("IdTipDoc"));
						RolId = Integer.parseInt(request.getParameter("IdTipoPersona"));						
						neg.insertarPersona(NomPersona, NomPaterno, NomMaterno, Sexo, NumDocumento, NomEmail, NomPass, FechaNaciento, NumCelular, Estado, IdTipDoc, RolId);
						msg = "Registrado Satisfactoriamente";
						
						request.setAttribute("MENSAJE", msg);
						
						rd = request.getRequestDispatcher("Index.jsp");
						rd.forward(request, response);
					}
					else{
						msg="Debe ingresar los campos necesarios";
						request.setAttribute("MENSAJE", msg);
						rd = request.getRequestDispatcher("Index.jsp");
						rd.forward(request, response);
					
						}
					}
				 catch (DAOExcepcion e) {
						System.out.print("Falló: " + e.getMessage());
					} 
	}
	
}
